//
//  ViewController.m
//  YYModel的使用
//
//  Created by 梁森 on 2018/1/9.
//  Copyright © 2018年 ----. All rights reserved.
//

#import "ViewController.h"
#import <YYModel.h>
#import "Person.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    NSDictionary * perDic = @{@"id":@"100",@"name":@"梁森", @"age":@"11", @"wife":@"jjj"};
    Person * personModel = [Person yy_modelWithDictionary:perDic];
    NSLog(@"%@", personModel.name);
    NSLog(@"%@", personModel.age);
    NSLog(@"%@", personModel.wife);
    NSLog(@"%@", personModel.ID);
    
    NSString *file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"product.data"];
    BOOL successOrNot = [NSKeyedArchiver archiveRootObject:personModel toFile:file];
    NSLog(@"归档成功与否：%d", successOrNot);
    
    //解档
    Person *model  = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
    NSLog(@"ID:%@=====Name:%@====age:%@",model.ID, model.name, model.age);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
